package com.hkj.configcenter.admin;

import com.hkj.configcenter.admin.filter.LoginFilter;
import com.hkj.configcenter.core.processor.ConfigBeanFactoryPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.Filter;

/**
 * 配置中心后台springboot启动类
 */
@RestController
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class AppConfigCenter {

    @Bean
    public ConfigBeanFactoryPostProcessor getConfigBeanFactoryPostProcessor() {
        return new ConfigBeanFactoryPostProcessor();
    }

    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        // 登录过滤器
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(loginFilter());
        registration.addUrlPatterns("/config/center/*");
        registration.setName("loginFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean(name = "loginFilter")
    public Filter loginFilter() {
        return new LoginFilter();
    }

    public static void main(String[] args) {
        SpringApplication.run(AppConfigCenter.class, args);
    }

}
